package com.ruoyi.project.xkx.school.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.xkx.school.domain.XkxSchool;
import com.ruoyi.project.xkx.school.mapper.XkxSchoolMapper;
import com.ruoyi.project.xkx.school.service.IXkxSchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 校区Controller
 *
 * @author ...
 * @date 2021-05-09
 */
@RestController
  @RequestMapping("/school/school")
public class XkxSchoolController extends BaseController {
  @Autowired
  private IXkxSchoolService xkxSchoolService;

  @Autowired
  private XkxSchoolMapper schoolMapper;
  /**
   * 全部校区
   */
  @GetMapping("/listSchoolAll")
  public AjaxResult getSchoolListAll(){
    //List<XkxSchool> schoolList = schoolMapper.selectList(new QueryWrapper<XkxSchool>().select("school_id","school_name","school_note"));
    List<XkxSchool> list = xkxSchoolService.list();
    return AjaxResult.success(list);
  }
  /**
   * 查询校区列表
   */
  @PreAuthorize("@ss.hasPermi('school:school:list')")
  @GetMapping("/list")
  public TableDataInfo list(XkxSchool xkxSchool) {
    startPage();
    List<XkxSchool> list = xkxSchoolService.selectXkxSchoolList(xkxSchool);
    return getDataTable(list);
  }

  /**
   * 导出校区列表
   */
  @PreAuthorize("@ss.hasPermi('school:school:export')")
  @Log(title = "校区", businessType = BusinessType.EXPORT)
  @GetMapping("/export")
  public AjaxResult export(XkxSchool xkxSchool) {
    List<XkxSchool> list = xkxSchoolService.selectXkxSchoolList(xkxSchool);
    ExcelUtil<XkxSchool> util = new ExcelUtil<XkxSchool>(XkxSchool.class);
    return util.exportExcel(list, "校区数据");
  }

  /**
   * 获取校区详细信息
   */
  @PreAuthorize("@ss.hasPermi('school:school:query')")
  @GetMapping(value = "/{schoolId}")
  public AjaxResult getInfo(@PathVariable("schoolId") Integer schoolId) {
    return AjaxResult.success(xkxSchoolService.selectXkxSchoolById(schoolId));
  }

  /**
   * 新增校区
   */
  @PreAuthorize("@ss.hasPermi('school:school:add')")
  @Log(title = "校区", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@RequestBody XkxSchool xkxSchool) {
    return toAjax(xkxSchoolService.insertXkxSchool(xkxSchool));
  }

  /**
   * 修改校区
   */
  @PreAuthorize("@ss.hasPermi('school:school:edit')")
  @Log(title = "校区", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@RequestBody XkxSchool xkxSchool) {
    return toAjax(xkxSchoolService.updateXkxSchool(xkxSchool));
  }

  /**
   * 删除校区
   */
  @PreAuthorize("@ss.hasPermi('school:school:remove')")
  @Log(title = "校区", businessType = BusinessType.DELETE)
  @DeleteMapping("/{schoolIds}")
  public AjaxResult remove(@PathVariable Integer[] schoolIds) {
    return toAjax(xkxSchoolService.deleteXkxSchoolByIds(schoolIds));
  }
}
